﻿Imports System.Data.OleDb
Imports System.Xml
Imports System.ServiceModel.Syndication



Partial Public Class rss
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.ContentType = "application/rss+xml"

        Dim PetsFeed As New SyndicationFeed

        PetsFeed.Title = TextSyndicationContent.CreatePlaintextContent("Pets Care in london")
        PetsFeed.Description = TextSyndicationContent.CreatePlaintextContent("The few most recent Pets added to The PetsCare.")
        PetsFeed.Links.Add(SyndicationLink.CreateSelfLink(New Uri(okURL("Home.aspx"))))
        PetsFeed.Language = "en-us"

        Dim oledbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        oledbConn.Open()
        Dim cmdQuery As String = "SELECT TOP 5 * from PetDetails"
        Dim dbconn = New OleDbCommand(cmdQuery, oledbConn)
        Dim dbread = dbconn.ExecuteReader()

        Dim myitems As New List(Of SyndicationItem)
        While dbread.Read()
            Dim sitem As New SyndicationItem
            sitem.Title = makersstxt(dbread("PetName"))
            sitem.Summary = makersstxt(dbread("Description"))
          
            myitems.Add(sitem)
        End While

        PetsFeed.Items = myitems

        Dim feedwriter As XmlWriter = XmlWriter.Create(Response.OutputStream)

        Dim rssformatter = New Rss20FeedFormatter(PetsFeed)

        rssformatter.WriteTo(feedwriter)

        feedwriter.Close()
    End Sub
    Private Function makersslink(ByVal SomeLoc As String) As SyndicationLink
        Return SyndicationLink.CreateAlternateLink(New Uri(SomeLoc))
    End Function

    Private Function makersstxt(ByVal somestring As String) As SyndicationContent
        Return TextSyndicationContent.CreatePlaintextContent(somestring)
    End Function

    Private Function okURL(ByVal urlstr As String)
        Return Request.Url.GetLeftPart(UriPartial.Authority) & ResolveUrl(urlstr)

    End Function
End Class